<?php
namespace app\admin\controller;
use think\Controller;
class User extends Controller
{
	private $obj;
    public function _initialize(){
        $this->obj=model('user');
    }
    /**
     * 用户首页
     */
    public function index()
    {
    	$list=$this->obj->getUser();
    	// var_dump($list);exit;
        return $this->fetch('',['list'=>$list]);
    }
    /**
     * 用户删除
     */
    public function del(){
    	$id=input('id');
    	// var_dump($id);exit;
    	if($this->obj->where('id',$id)->delete()){
    		$this->success("删除成功",'user/index');
    	}
    }
    //用户编辑
    public function edit(){
        $id=input('id');
        // var_dump($account_id);exit;
        if (request()->isPost()) {
            $data['username']=input('post.username');
            $data['password']=md5(input('post.pwd'));
            $data['update_time']=time();
            $opwd=input('post.opwd');
            $id=input('id');
            $is_find=$this->obj->where(['id'=>$id])->find();
            if($is_find){
                if($is_find['password']!=md5($opwd)){
                    return $this->error("密码错误");
                }
            }
            // var_dump($account_id);exit;
            if($this->obj->where('id',$id)->update($data)){
                $this->success("修改成功",'user/index');
            }
        }  
        $info=$this->obj->where('id',$id)->find();
        // var_dump($account);exit;
        return $this->fetch('',['info'=>$info]);
    }
}
